package com.dsk.connector.commons.utils;

public class DDLUtils {
    /**
     * 删除DDL语句中的注释
     * @param ddl
     * @return
     */
    public static String removeComment(String ddl) {
        ddl=ddl.replaceAll("/\\*(.\r?\n?)+\\*/"," ");
        ddl=ddl.replaceAll("--\\s.+\r?\n"," ");
        ddl=ddl.replaceAll("\\#.+\r?\n"," ");
        String newDDl=ddl.replaceAll("^\\s*\r?\n","");
        while (!newDDl.equals(ddl)){
            ddl=newDDl;
            newDDl=ddl.replaceAll("^\\s*\r?\n","");
        };

        newDDl=ddl.replaceAll("^\\s*\r","");
        while (!newDDl.equals(ddl)){
            ddl=newDDl;
            newDDl=ddl.replaceAll("^\\s*\r","");
        };
        return ddl.trim();
    }
}
